package com.zcf.gameController.gameUtils;

import com.zcf.gameController.WebSocketBull;
import com.zcf.pojo.*;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author jj
 * @date 2019/11/18 11:57
 */
public class AccountThread extends Thread{
    private List<UserBean> users;
    private String roomName;
    private Integer roomGrade;
    private Integer gameType;
    public AccountThread(  List<UserBean> users, Integer roomGrade,String roomName,Double pumping,Integer gameType){
        this.users = users;
        this.roomName=roomName;
        this.roomGrade=roomGrade;
        this.gameType=gameType;
    }

    @Override
    public void run() {
        long time = System.currentTimeMillis();
        for (UserBean u1:users) {
            User user=new User();
            user.setId(Long.valueOf(u1.getId()));
            User u = user.selectById();

            if (u!=null){
                u.setMoney(u1.getMoney());
                boolean b = u.updateById();
                if (b){
                    UserRecord userRecord=new UserRecord();
                    userRecord.setUserid(u.getId());
                    userRecord.setRoomid(Integer.valueOf(roomName));
                    userRecord.setCreateTime(new Date());
                    userRecord.setNickname(u.getWxname());
                    userRecord.setWximg(u.getWximg());
                    userRecord.setRoomGrade(roomGrade);
                    userRecord.setUuid(time);
                    userRecord.setGameType(gameType);
                    if (u1.getTotal()!=0){
                        userRecord.setSumWinnumber(u1.getTotal());
                    }else {
                        userRecord.setSumWinnumber(u1.getSumWinnumber());
                    }
                    userRecord.insert();
                    if (u1.getSumWinnumber()>0){
                        PumpingLog pumpingLog=new PumpingLog();
                        pumpingLog.setCreateTime(new Date());
                        pumpingLog.setPumping(u1.getSumWinnumber());
                        pumpingLog.setRoomGrade(roomGrade);
                        pumpingLog.setUserid(u.getId());
                        pumpingLog.setRoomid(Integer.valueOf(roomName));
                        pumpingLog.setGameType(gameType);
                        pumpingLog.insert();
                    }
                }
            }
        }
        System.out.println("----------------------------用户数据持久化成功！！！-----------------------------------");
    }
}
